<script>
import {reactive} from 'vue';
import { RouterLink, RouterView } from 'vue-router';
import Aside from '@/components/index/Aside.vue';
import Header from '@/components/index/header.vue'
import api from '@/utils/request';
import { useRouter } from 'vue-router';
import {removeToken , getToken } from '@/hooks/auth.js';
import {user} from'@/stores/user'

export default{
  components: { Aside,Header },
  setup(){
    const router = useRouter()
    
    if(getToken()!=null){
      api.get('admin-info/getInfo?token='+getToken())
      .then((response) => {
        //存储用户信息
        const userimpl =user();
        userimpl.userstor.id=response.data.admin.adminId
        userimpl.userstor.username=response.data.admin.adminUsername
        userimpl.userstor.phone=response.data.admin.adminPhone
        userimpl.userstor.avatar=response.data.admin.adminAvatar
        userimpl.userstor.email=response.data.admin.adminEmail
      })
      .catch((error) => {
        removeToken();
        router.push('/')
      });
    }else{
      router.push('/')
    }
  }
}


</script>
<template>
  <div class="common-layout">
    <el-container class="layout-container-demo">
      <el-header>
        <Header></Header>
      </el-header>
      <el-container>
        <Aside></Aside>
        <el-main>
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>


<style>

.el-header{
  background-color: #409EFF;
  padding: 0 80px;
  height: 60px;
  line-height: 60px;
}
.el-aside{
  background-color: #C0C4CC;
  height: 909px;
}
.el-main{
  /* background-color: rebeccapurple; */
}

</style>